<?php
class SaveType extends Action {
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );

		$page_type = rqsts ( array ('page_type_id', 'page_type', 'page_type_name', 'default_template', 'note' ), true );
		
		$typeModel = new WebPageTypeModel ();
		
		if (empty ( $page_type ['page_type_id'] )) {
			unset ( $page_type ['page_type_id'] );
		}
		// 验证用户数据的合法性
		$valid = $this->validate ( 'page_type', $page_type, $typeModel );
		
		if ($valid === true) { // 用户数据合法
			$rst = $typeModel->save ( $page_type );
			if (! empty ( $rst )) {
				if (! rqset ( 'goon' )) {
					sess_add ( 'page_tip_info', '<strong>恭喜,</strong>页面类型保存成功.' );
					Response::redirect ( './?Ctlr=EditType&suc=1&tid=' . $rst ['page_type_id'] );
				} else {
					Response::redirect ( './?Ctlr=AddType' );
				}
			} else {
				sess_add ( 'page_type_info', $page_type );
				sess_add ( 'page_tip_info', '<strong>出错啦!</strong>' . $groupModel->last_error_msg () );
				Response::redirect ( $this->referer );
			}
		}
		sess_add ( 'page_type_error', $valid );
		sess_add ( 'page_type_info', $page_type );
		Response::redirect ( $this->referer );
	}
}